<template>
	<view class="content">
		<view class="order_one">
			<view class="order_one_left" v-for="item in goosList" :key='item.id'>
				<image :src="item.goods_image" mode=""></image>
				<view class="order_one_text">
					<view class="order_ones">
						<text>{{item.goods_name}}</text>
						<text class="price">￥{{item.price}}</text>
					</view>
					<view class="order_ones">
						<text class="gg">{{item.ertitle}}</text>
						<text class="gg">X{{item.num}}</text>
					</view>
				</view>
			</view>
			<!-- 	<view class="order_one_left">
				<image src="../../../static/images/a7.png" mode=""></image>
				<view class="order_one_text">
					<view class="order_ones">
						<text>马来西亚猫山王榴莲1个装</text>
						<text class="price">￥269</text>
					</view>
					<view class="order_ones">
						<text class="gg">规格：1.8-2.2kg（液氮冷冻）</text>
						<text class="gg">2</text>
					</view>
				</view>
			</view> -->
			<view class="order_one_item">
				<!-- 	<view class="order_one_yf">
					<text>运费</text>
					<text class="gg">￥0.00</text>
				</view> -->
				<view class="order_one_yf">
					<text>备注</text>
					<text class="gg">{{info.buyer_message}}</text>
				</view>
			</view>
			<view class="order_one_sh">
				<view class="order_sh">
					<!-- <text>待支付</text> -->
					<!-- <text>退款</text> -->
				</view>
				<view class="order_qrs">
					<text></text>
					<text class="zj"><text class="hj">合计</text>￥{{info.oldmoney}}</text>
				</view>
			</view>
		</view>
		<view class="refund">
			<view class="refund_item">
				<text>售后原因</text>
				<text class="bt">(必填)</text>
			</view>
			<view class="textarea_box">
				<textarea class="textarea" placeholder="补充详细售后原因，有利于商家更快的帮您处理" maxlength="200" @input="descInput" v-model="desc" />
				<view class="num">{{ desc.length }}/200</view>
			</view>
			<view class="sctp">
				<view>
					<text>最多上传三张</text>
				</view>
				<!-- <view class="sctp_img">
					<image  src="../../../static/images/a11.png" mode=""></image>
				</view> -->
				<view class="add-img-box">
					<view class="add-img-item" v-for="(item, index) in imgList" :key="index">
						<image class="add-img" @click="imgInfo(index)" :src="item.path" mode="aspectFill"></image>
						<image  class="add-img-del" @click="delImg(index)" src="../../../static/images/a14.png"></image>
					</view>
					<view v-if="imgList.length < 3 " class="add-img-item" @click="openCamera">
						<image class="add-img" src="../../../static/images/a11.png"></image>
					</view>
				</view>
			</view>
		</view>
		<view class="sale_bottom"  @click="receipt">
			<button type="default">提交</button>
		</view>	
	</view>
</template>

<script>
	export default {
		data() {
			return {
				desc: '', //监听文本域的字数
				imgList: [],
				cloudimgList: [],
				imgCount: 3,//最多支持9张上传，可以修改
				id:'',
			goosList:[],
			info:{},
			img:[]
			};
		},
		onLoad(options) {
			this.id = options.oid
			
		},
		onShow() {
		this.Detailinfo()
		},
		methods:{
			Detailinfo(){
				this.$ajax(
				this.apiList.orderdetail,
				{
					oid:this.id
				},'POST'
				).then(res=>{
					this.info = res.data
					this.goosList = res.data.goods
						// console.log(this.info )
				})
			},
			
			descInput(e) {
				this.remnant = e.detail.value.length;
			},
			receipt() {
				uni.showModal({
					content: '提交成功，请耐心等候',
					 showCancel: false,
					 buttonText: '确定',
					success:(res)=> {
						console.log(this.img.toString())
						if (res.confirm) {
							this.$ajax(
							this.apiList.afters,
							{
								oid:this.id,
								bz:this.desc,
								images:this.img.toString()
							},
							'POST'
							).then(res=>{
								this.$sToast(res.msg)
								uni.navigateTo({
									url:'../sale/sale?oid='+this.id
								})
							})
						} 
					}
				})
			},
					

			imgInfo(i) {
				let tempList = [];
				this.imgList.forEach(img => {
					tempList.push(img.path);
				});
				console.log(tempList);
				//显示图片
				uni.previewImage({
					current: i,
					loop: false,
					urls: tempList,
					indicator: 'default'
				});
			},
			delImg(i) {
				uni.showModal({
					content: '确定删除这张吗',
					success: res => {
						if (res.confirm) {
							this.imgList.splice(i, 1);
							this.imgCount++;
						} else if (res.cancel) {
							
						}
					}
				});
			},
			delcloudImg(i) {
				var _self = this;
				uni.showModal({
					content: '确定删除云服务器上面这张图吗',
					success: res => {
						if (res.confirm) {
							this.$cloud.deleteFile(
							  {
							    fileList: [this.cloudimgList[i]],
							    success(res){	
								},
							    fail(err){
									console.log(err);								
								},
							    complete(res){
									uni.showToast({
										title: '删除成功！',
										icon: 'none'
									});
									_self.cloudimgList.splice(i, 1);
								}							
							  }					  
							);					
						} else if (res.cancel) {
							
						}
					}
				});
			},
			urlTobase64(url) {
							 var that = this
							 var toBase64Url;
							 uni.request({
							 url: url,
							 method: 'GET',
							 responseType: 'arraybuffer',
							 success: async res => {
							 let base64 = wx.arrayBufferToBase64(res.data); //把arraybuffer转成base64
							 toBase64Url = 'data:image/jpeg;base64,' + base64; //不加上这串字符，在页面无法显示
								let image = []
								image.push(toBase64Url)
								this.$ajax(
									this.apiList.shang, {
										img: image.toString()
									},
									'POST',
								).then(res => {
									if(res.code){
									 this.img.push(res.data) 
									}
								})
							 }
					});
			},
			
			openCamera() {
				uni.chooseImage({
					sourceType:['camera','album '],
					count: this.imgCount,
					sizeType: ['compressed'],
					success: e => {
						this.imgList = [...e.tempFiles,...this.imgList];
						this.imgCount = 9 - this.imgList.length;
						// console.log('imgCount', this.imgCount);
						// console.log(this.imgList )
						// console.log(this.imgList[0])
						for(var i = 0; i< this.imgList.length; i++){
								this.urlTobase64(this.imgList[i].path)
						}
					}
				});
			},
			
		}
			
	}
</script>

<style lang="scss">
	.content{
		background: #F5F5F5;
		//height: 100vh;
		.order_one {
			margin: 20rpx;
			background: #fff;
			border-radius: 15rpx;
			.order_one_left {
				display: flex;
				padding: 20rpx;
				image {
					width: 128rpx;
					height: 128rpx;
				}
				.order_one_text {
					width: 80%;
					font-size: 24rpx;
					color: #212121;
					font-weight: 400;
					font-family: PingFang SC;
					text {
						display: block;
					}
					.order_ones {
						display: flex;
						justify-content: space-between;
						width: 100%;
						padding-bottom: 20rpx;
					}
					.price {
						color: red;
					}
					.gg {
						color: #BDBDBD;
						font-size: 20rpx;
					}
				}
			}
		
			.order_one_yf {
				display: flex;
				justify-content: space-between;
				padding: 20rpx 20rpx 10rpx 20rpx;
				text {
					font-size: 20rpx;
				}
				.gg {
					color: #BDBDBD;
				}
			}
			.order_one_sh {
				display: flex;
				justify-content: space-between;
				padding: 20rpx 20rpx 10rpx 20rpx;
		
				.order_sh {
					text {
						color: #FCBB21;
						font-size: 24rpx;
						border: 1px solid #FCBB21;
						padding: 5rpx 20rpx;
						border-radius: 20rpx;
						margin-right: 20rpx;
					}
				}
				.order_qrs {
					text {
						color: #BDBDBD;
					}
		
					.zj {
						padding-left: 10rpx;
						font-size: 28rpx;
						color: red;
		
						.hj {
							font-size: 28rpx;
							color: #212121;
						}
					}
				}
				text {
					font-size: 24rpx;
				}
			}
		
		}
		.refund{
			background: #fff;
			margin: 20rpx;
			text{
				font-size: 28rpx;
			}
			.textarea_box{
				background: #F5F5F5;
				margin: 20rpx;
				padding: 20rpx;
				border-radius: 15rpx;
				height: 200rpx;
				textarea{
					font-size: 20rpx;
					height: 200rpx;
					color: #BDBDBD;
				}
				.num{
					font-size: 20rpx;
					color: #BDBDBD;
					text-align: right;
					margin-top: -20rpx;
				}
			}
			.refund_item{
				padding: 20rpx;
				.bt{
					color: #FCBB21;
					font-size: 20rpx;
					padding-left: 20rpx;
				}
			}
			.sctp{
				padding: 20rpx;
				.add-img-box{
					display: flex;
					align-items: center;
					position: relative;
					.add-img-del{
						width: 30upx;
						height: 30rpx;
						position: absolute;
						top:0;
						left:80upx ;
					}
				}
				image{
					width: 100rpx;
					height: 100rpx;
					padding-top: 20rpx;
					margin-left: 20rpx;
				}
				text{
					display: block;
					font-size: 20rpx;
					color: #BDBDBD;
					
				}
			}
	
		}	
		.sale_bottom{
			margin-top: 106rpx;
			padding-bottom: 20rpx;
			button{
				height: 88rpx;
				border-radius:88rpx ;
				font-size: 28rpx;
				color: #fff;
				background: #8BDD8E;
				line-height: 88rpx;
			}
		}		
		
	}
</style>
